package com.czjtxy.extraTerm.controller.usermodule;

import com.czjtxy.extraTerm.entity.DO.Tuser;
import com.czjtxy.extraTerm.server.UserService;
import com.czjtxy.extraTerm.serverImpl.UserServiceImpl;
import com.czjtxy.extraTerm.util.Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @program: staff-house
 * @author: MingYi
 * @create: 2021/07/04 08:37
 */
@WebServlet(name = "AddUserServlet", value = "/AddUserServlet")
public class AddUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Tuser tuser = new Tuser();
        tuser.setUserName(req.getParameter("username"));
        tuser.setLoginName(req.getParameter("loginname"));
        tuser.setStatus(Util.stringToInt(req.getParameter("status")));
        tuser.setPassword(req.getParameter("password"));

        UserService userService = new UserServiceImpl();
        try {
            userService.addUser(tuser);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        req.getRequestDispatcher("/UserServlet").forward(req, resp);
    }
}
